<template>
	<div class="login">
		<table>
			<tr><td colspan="2" class="td1" cellspacing="0">ERP管理系统</td></tr>
			<tr>
				<td colspan="2" align="center">
				</td>
			</tr>
			<tr style="margin-top:10px">
				<td align="right" style="width:120px;font-family:Microsoft YaHei;font-size:16px;">帐&nbsp;&nbsp;&nbsp;&nbsp;号：</td><td align="left" ><input type="text" v-model="txtname" @blur="checkName()" /></td>
			</tr>
			<tr style="margin-top:20px">
				<td align="right" style="width:120px;font-family:Microsoft YaHei;font-size:16px;">密&nbsp;&nbsp;&nbsp;&nbsp;码：</td><td align="left"><input type="password" v-model="txtpass" @blur="checkPass()"/></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<span v-model="error2" style="color:#ec3f3f;font-size:12px">{{error2}}</span>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<el-button type="primary" style="width:120px;" @click="Login()">登&nbsp;&nbsp;&nbsp;&nbsp;陆</el-button>
				</td>
			</tr>
		</table>
	</div>
</template>

<script>
	export default {
	  name: 'Login',
		data(){
			return{
				txtname:'',
				txtpass:'',
				error2:'',
				emp:{},
				
				}  
		},
	  methods:{
		  checkName(){
		  	this.error2='';
		  	if(this.txtname==''){
		  		this.error2='请输入帐号';
		  	}else if(isNaN(this.txtname)==true){
		  		this.error2='帐号请输入数字';
		  	}
		  },
		  checkPass(){
		  	if(this.txtname!=''){
		  		if(this.txtpass==''){
		  			this.error2='请输入密码';
		  		}else if(this.txtpass.length<6){
		  			this.error2='密码长度小于6位';
		  		}else{
		  			this.error2=''
		  		}
		  	}
		  },
		  Login(){
				
		  	if(this.error2==''){
					var eid=this.txtname;
					var pass=this.txtpass;
					this.$axios.post("logins?id="+eid+"&pwd="+pass+"").then(v=>{
						console.log(v)
						if(v.data){
							this.emp=v.data;
							if(JSON.stringify(this.emp)!="{}"){
								 this.$router.push({
											/* name: 'home',
											params: {
												user: this.emp,
											} */
											path:'/home/',
											query: {
												user: this.emp,
											  }
									})
								//location.href='#/home';
							}else{
								this.error2='用户名或密码错误！';
							}
							
						}else{
							alert("出错了！"+ex);
						}
					}).catch(ex=>{
						alert("出错了！"+ex);
						this.error2=ex;
					})					
				}
		  }
		},
	}
	
</script>
	
<style>
.el-submenu__title {
		font-weight:bold;
	}
.login{
	background:#A0CFFF;
	padding:120px;
	height: 100%;
	
}
.login table{
	background:white;
	width:380px;
	height:260px;
	margin:0px auto;
	border-collapse: collapse;
	border-spacing: 0; 
	border:1px solid #A0CFFF;
	border-radius:6px;
	
}

.login table tr td input{
		width:180px;
		height:24px;
		 outline:none;
		border:solid 1px #bbb;
		border-radius:4px;
		padding-left:10px;
}
input:-webkit-autofill { box-shadow: 0 0 0px 1000px white inset !important;}
.login table tr td{
	height:20px;
}
.td1{
	color:white;
	text-align: center;
	font-size:20px;
	border-radius: 6px 6px 0 0;
	background:#2CA3E7;
}
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
	height: 100%;
}
</style>
